package com.kgc.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kgc.dao.BrandMapper;
import com.kgc.entity.Brand;
import com.kgc.entity.BrandExample;
import com.kgc.service.BrandService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BrandServiceImpl implements BrandService {
    @Autowired
    private BrandMapper brandMapper;
    public long countByExample(BrandExample example) {
        return 0;
    }

    public int deleteByExample(BrandExample example) {
        return 0;
    }

    public int deleteByPrimaryKey(Integer id) {
        return brandMapper.deleteByPrimaryKey(id);
    }

    public int insert(Brand record) {
        return brandMapper.insert(record);
    }

    public int insertSelective(Brand record) {
        return 0;
    }

    public List<Brand> selectByExample(BrandExample example) {
        return brandMapper.selectByExample(example);
    }

    public Brand selectByPrimaryKey(Integer id) {
        return brandMapper.selectByPrimaryKey(id);
    }

    public int updateByExampleSelective(Brand record, BrandExample example) {
        return 0;
    }

    public int updateByExample(Brand record, BrandExample example) {
        return 0;
    }

    public int updateByPrimaryKeySelective(Brand record) {
        return 0;
    }

    public int updateByPrimaryKey(Brand record) {
        return brandMapper.updateByPrimaryKey(record);
    }

    public PageInfo findBrand(int page, int limit) {
        PageHelper.startPage(page,limit);
        List<Brand> list=brandMapper.selectByExample(new BrandExample());
        PageInfo<Brand> pageInfo=new PageInfo<Brand>(list);
       return pageInfo;
    }

    public PageInfo<Brand> findAll(int page, int limit,Brand brand) {
        PageHelper.startPage(page,limit);
        BrandExample brandExample=new BrandExample();
        BrandExample.Criteria criteria = brandExample.createCriteria();
        if (brand!=null&&!StringUtils.isEmpty(brand.getName())){
            criteria.andNameLike("%"+brand.getName()+"%");
        }
        if(brand!=null&&brand.getStatus()!=null){
            criteria.andStatusEqualTo(brand.getStatus());

        }

        List<Brand> list = brandMapper.selectByExample(brandExample);
        PageInfo<Brand> pageInfo=new PageInfo<Brand>(list);
        return pageInfo;

    }

}
